<?php

declare(strict_types=1);
/**
 * Author: Zane
 * Email: 873934580@qq.com
 * Date: 2023/7/15.
 */

namespace App\Service;

use App\Service\Contract\ArchiveInterface;
use Zane\View\Service\Transfer;

class ArchiveService implements ArchiveInterface
{
    public function read(Transfer $transfer): array
    {
        $tid = $transfer->get('tid', 1);
        $cateIds = [2, 3, 4, 12];
        $table = 'liquor';
        if (\in_array((int) $tid, $cateIds, true) || \is_array($tid)) {
            $table = 'article';
        }
        $model = modelBuild($table)->newQuery();
        if (\is_array($tid)) {
            $model->whereIn('category_id', $tid);
        } else {
            $model->where('category_id', $tid);
        }
        if ($row = (int) $transfer->get('row')) {
            $model->limit($row);
        }
        if (!blank($transfer->getOrder())) {
            foreach ($transfer->getOrder() as $key => $val) {
                $model->orderBy($key, $val);
            }
        }

        return $model->get()->toArray();
    }

    public function details(Transfer $transfer): void
    {
    }

    public function lists(): array
    {
        return [];
    }
}
